package com.mf.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mf.entity.User;
import com.mf.entity.UserDayHistory;
import com.mf.entity.UserTransferAccounts;
import com.mf.service.IUserDayHistoryService;
import com.mf.service.IUserService;
import com.mf.service.IUserTransferAccountsService;
import com.mf.utils.Result;
import com.mf.vo.UserDayHistoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author mf
 * @since 2024-05-16
 */
@RestController
@RequestMapping("/stock/user")
@Tag(name = "用户相关")
public class UserController {
    @Resource
    private IUserService userService;

    @Resource
    private IUserTransferAccountsService userTransferAccountsService;
    @Resource
    private IUserDayHistoryService userDaysService;

    @Operation(summary = "新增用户")
    @PostMapping("/addUser")
    public Result<Boolean> addUser(@RequestBody User user)
    {
       return Result.success(userService.save(user));
    }
    @Operation(summary = "根据id查询用户")
    @PostMapping("/findUser")
    public Result<List<User>> findUser(@RequestParam("id") Integer id)
    {
        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.eq(User::getId,id);
        return Result.success(userService.list(userLambdaQueryWrapper));
    }



    @Operation(summary = "添加用户转账记录")
    @PostMapping("/UserTransferAccountsAdd")
    public Integer add(@RequestBody UserTransferAccounts userTransferAccounts) {
        return userTransferAccountsService.add(userTransferAccounts);
    }

    @Operation(summary = "查询每天用户金额变动记录历史")
    @PostMapping("/findUserDayHistory")
    public Result<Page<UserDayHistory>> findUserDayHistory(@RequestBody UserDayHistoryVo userDayHistory) {
        return Result.success(userDaysService.findUserDayHistory(userDayHistory));
    }

    @Operation(summary = "查询所有用户")
    @GetMapping("/findAllUser")
    public Result<List<User>> findAllUser()
    {
        return Result.success(userService.list());
    }
}
